package com.nineclock.system.controller;

import com.nineclock.common.entity.Result;
import com.nineclock.system.dto.SysCompanyUserDTO;
import com.nineclock.system.service.SysCompanyUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @author 黑马程序员
 * @Company http://www.ithiema.com
 * @Version 1.0
 */
@RestController
@RequestMapping("/companyUser")
public class SysCompanyUserController {
    
    @Autowired
    SysCompanyUserService companyUserService;
    
    @GetMapping("/queryone")
    public Result<SysCompanyUserDTO> findCompanyUserByMobile(String mobile) {
        SysCompanyUserDTO companyUserDTO = companyUserService.queryOne(mobile);
        return Result.success(companyUserDTO);
    }
    
    //根据企业ID查询企业的主管理员信息
    @GetMapping("/queryAdminByCompanyId")
    public Result<SysCompanyUserDTO> queryAdminByCompanyId(Long companyId) {
        SysCompanyUserDTO companyUserDTO = companyUserService.queryAdminByCompanyId(companyId);
        return Result.success(companyUserDTO);
    }
    
    @GetMapping("/queryAllUserByCompanyId")
    public Result<List<SysCompanyUserDTO>> queryAllUserByCompanyId(Long companyId) {
        List<SysCompanyUserDTO> companyUserDTOList = companyUserService.queryAllUserByCompanyId(companyId);
        return Result.success(companyUserDTOList);
    }
    
    @GetMapping("/query")
    public Result<List<SysCompanyUserDTO>> queryCompanyUser(
        @RequestParam(value = "userId", required = false) Long userId,
        @RequestParam(value = "companyId", required = false) Long companyId) {
        List<SysCompanyUserDTO> companyUserDTOList = companyUserService.queryCompanyUser(userId, companyId);
        return Result.success(companyUserDTOList);
    }
    
    @GetMapping("/createUserId")
    public Result<SysCompanyUserDTO> findCompanyUserByCreateUserId(@RequestParam(value = "createUserId") Long createUserId) {
        SysCompanyUserDTO companyUserDTO = companyUserService.findCompanyUserByCreateUserId(createUserId);
        return Result.success(companyUserDTO);
    }
    
    @GetMapping("/queryNameById")
    public Result<SysCompanyUserDTO> queryNameById(@RequestParam(value = "createUserId") Long createUserId) {
        SysCompanyUserDTO companyUserDTO = companyUserService.queryNameById(createUserId);
        return Result.success(companyUserDTO);
    }
    
    @GetMapping("/queryDepartmentName")
    public Result<String> queryDepartmentName(@RequestParam(value = "username") String username, @RequestParam(value = "companyId") Long companyId) {
        String departmentName = companyUserService.queryDepartmentName(username, companyId);
        return Result.success(departmentName);
    }
}
